package cn.colat.micse.user.controller;

import cn.colat.micse.common.code.ResCode;
import cn.colat.micse.common.exception.GlobalServerException;
import cn.colat.micse.common.pojo.vo.ResBody;
import cn.colat.micse.user.feign.OrderOpenFeignService;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/index")
@Api(tags = {"用户首页接口"})
@AllArgsConstructor
public class IndexController {
    private OrderOpenFeignService orderOpenFeignService;

    @ApiOperation("首页健康检查")
    @RequestMapping("/health")
    public ResBody<String> index() {
        return ResBody.success("User Service Is running");
    }


    @PostMapping("/order-list")
    public ResBody<JSONObject> orderList() {
        ResBody<JSONObject> res = orderOpenFeignService.orderList();
        if (!res.success) {
            throw new GlobalServerException(ResCode.SERVER_ERROR);
        }
        return ResBody.success(res.data);
    }
}
